import React from "react";
import { useRouter } from 'next/router'
import { Button, Checkbox, Form, Input,Card } from "antd";
import { login } from "@/services/user";
import { log } from "console";


function Login() {
    const router = useRouter();
    const onFinish = async(values: any) => {
        let data = await login(values);
        if(data.status == 1){
            router.push("/manage");
        }
    };
    
    const onFinishFailed = (errorInfo: any) => {
        console.log("Failed:", errorInfo);
    };
    return <Card title="登录" style={{ width: 500,margin:"auto" }}>
    <Form
        name="basic"
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        style={{ maxWidth: 600 }}
        onFinish={onFinish}
        onFinishFailed={onFinishFailed}
        autoComplete="off"
    >
        <Form.Item
            label="用户名"
            name="username"
            rules={[{ required: true, message: "Please input your username!" }]}
        >
            <Input />
        </Form.Item>

        <Form.Item
            label="密码"
            name="pwd"
            rules={[{ required: true, message: "Please input your password!" }]}
        >
            <Input.Password />
        </Form.Item>


        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
            <Button type="primary" htmlType="submit">
                Submit
            </Button>
        </Form.Item>
    </Form>
    </Card> 
}
export default Login;
